package com.orangelife.mobile.property.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.curry.android.adapter.FatherAdapter;
import com.curry.android.util.MoneyUtil;
import com.curry.orangelife.mobile.R;

import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 历史缴费详情的金额列表的适配器
 * <p/>
 * Created by wgf on 2016/5/11.
 *
 * @author wgf
 * @since v3.6.4
 */
public class PropertyBillHistoryDetailAdapter<T> extends FatherAdapter<T> {
    private Context mContext;
    private List<Map<String, Object>> mList;

    public PropertyBillHistoryDetailAdapter(Context context, List<Map<String, Object>> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @SuppressWarnings("unchecked")
    @Override
    public BaseAdapter setList(List<T> list) {
        this.mList = (List<Map<String, Object>>) list;
        return this;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_lv_property_history_detail, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(R.id.tvMoney,viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag(R.id.tvMoney);
        }
        Map<String, Object> map = mList.get(position);
        String costName = String.valueOf(map.get("feeTypeName"));
        String costValue = MoneyUtil.handleMoney(String.valueOf(map.get("amount")))+"元";
        String range = String.valueOf(map.get("range"));
        viewHolder.tvCostName.setText(costName);
        viewHolder.tvCostValue.setText(costValue);
        viewHolder.tvRange.setText(range);
        return convertView;
    }

    static class ViewHolder {
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

        @Bind(R.id.tvCostName)
        TextView tvCostName;
        @Bind(R.id.tvCostValue)
        TextView tvCostValue;
        @Bind(R.id.tvRange)
        TextView tvRange;
    }
}
